package com.panshi.controller.sysUser;

import com.panshi.api.SystemUserApi;
import com.panshi.po.SystemUserPo;
import com.panshi.result.Result;
import com.panshi.vo.SystemUserUpdateVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * 用户中心渲染数据
 */
@Controller
@Slf4j
public class UserCenterController {


    @Autowired
    SystemUserApi systemUserApi;

    //个人中心渲染数据
    @RequestMapping(value = "/userCenter/userInfo",method = {RequestMethod.GET})
    public ModelAndView userInfo(){

        ModelAndView modelAndView=new ModelAndView("sysUser/user_userInfo");

        Subject subject = SecurityUtils.getSubject();

        SystemUserPo systemUserPo = (SystemUserPo) subject.getSession().getAttribute("loginUser");

        log.info("用户中心查询出来的数据========{}",systemUserPo);

        modelAndView.addObject("systemUser",systemUserPo);

        return modelAndView;

    }

    //暂时还没有用到
    @RequestMapping(value = "/userCenter/update",method = {RequestMethod.POST})
    @ResponseBody
    public Result updateUser(SystemUserPo systemUserPo){

        log.info("修改用户信息前端穿来的数据为={}",systemUserPo);

        SystemUserUpdateVo systemUserUpdateVo=new SystemUserUpdateVo();

        systemUserUpdateVo.setId(systemUserPo.getId());

        systemUserUpdateVo.setNick(systemUserUpdateVo.getNick());

        systemUserUpdateVo.setPassword(systemUserUpdateVo.getPassword());

        systemUserUpdateVo.setState(systemUserPo.getState());

        systemUserUpdateVo.setType(systemUserPo.getType());

        systemUserUpdateVo.setUsername(systemUserPo.getUsername());

        systemUserUpdateVo.setUpdatedate(new Date());

        Integer str=systemUserApi.updateUser(systemUserUpdateVo).getData();

        log.info("修改用户后返回的数据======{}",str);

        return Result.genSuccessResult();
    }




}
